package controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import pojo.Teacher;
import pojo.Term;
import service.TeacherManager;
import service.TermManager;
import utils.Constents;
import utils.DataParse;
import utils.DataUtils;
import utils.SelectOptionContent;

@Controller
public class TeacherScheduleControllerJSP {

	@Autowired
	private TeacherManager teacherManager;

	@Autowired
	private TermManager termManager;


	@RequestMapping(value = "/jsp/teacher/schedule", method = RequestMethod.GET)
	public String getTeacherSchedule(Map<String, Object> map) {

		List<Term> terms = termManager.getResults(null);
		if (terms.size() == 0) {
			String html = DataUtils.getOptionInfoFromNetWork(Constents.URL_TEACHERKBFB);
			terms = SelectOptionContent.convertToTerm(DataParse.parseHTMLOption(html, ""));
			termManager.addInfoList(terms);
		}
		List<Teacher> teachers = teacherManager.getResults(null);
		if (teachers.size() == 0) {
			String html = DataUtils.getOptionInfoFromNetWork(Constents.URL_THEACHERKBFB_INFO);
			teachers = SelectOptionContent.convertToTeacher(DataParse.parseScriptOption(html, ""));

			teacherManager.addInfoList(teachers);
		}

		map.put("teachers", teachers);
		map.put("terms", terms);

		return "teacherSchedule";
	}

}
